package org.dromara.app.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.app.domain.vo.SkDailiShengqingVo;
import org.dromara.app.domain.bo.SkDailiShengqingBo;
import org.dromara.app.service.ISkDailiShengqingService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 代理申请信息
 *
 * @author Evacuation
 * @date 2024-07-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/SkDailiShengqing")
public class SkDailiShengqingController extends BaseController {

    private final ISkDailiShengqingService skDailiShengqingService;

    /**
     * 查询代理申请信息列表
     */
    @SaCheckPermission("app:SkDailiShengqing:list")
    @GetMapping("/list")
    public TableDataInfo<SkDailiShengqingVo> list(SkDailiShengqingBo bo, PageQuery pageQuery) {
        return skDailiShengqingService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出代理申请信息列表
     */
    @SaCheckPermission("app:SkDailiShengqing:export")
    @Log(title = "代理申请信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SkDailiShengqingBo bo, HttpServletResponse response) {
        List<SkDailiShengqingVo> list = skDailiShengqingService.queryList(bo);
        ExcelUtil.exportExcel(list, "代理申请信息", SkDailiShengqingVo.class, response);
    }

    /**
     * 获取代理申请信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("app:SkDailiShengqing:query")
    @GetMapping("/{id}")
    public R<SkDailiShengqingVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(skDailiShengqingService.queryById(id));
    }

    /**
     * 新增代理申请信息
     */
    @SaCheckPermission("app:SkDailiShengqing:add")
    @Log(title = "代理申请信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SkDailiShengqingBo bo) {
        return toAjax(skDailiShengqingService.insertByBo(bo));
    }

    /**
     * 修改代理申请信息
     */
    @SaCheckPermission("app:SkDailiShengqing:edit")
    @Log(title = "代理申请信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SkDailiShengqingBo bo) {
        return toAjax(skDailiShengqingService.updateByBo(bo));
    }

    /**
     * 删除代理申请信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("app:SkDailiShengqing:remove")
    @Log(title = "代理申请信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(skDailiShengqingService.deleteWithValidByIds(List.of(ids), true));
    }
}
